package com.luo.chengrui.module.sa.enums;

import java.util.Arrays;
import java.util.Optional;

public enum DataPermissionScopeEnum {
    ALL(1, "全部"),
    CUSTOM(2, "指定数据权限"),
    CUSTOM_CONTAIN_CHILD(3, "指定数据权限（含下级"),
    DEPT_AND_CLILD(4,  "所属部门权限（限组织权限时可选）"),
    DEPT_SELF(5, "仅本人数据权限（限组织权限时可选）");

    private Integer code;
    private String name;

    DataPermissionScopeEnum(Integer code, String name) {
        this.code = code;
        this.name = name;
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public static DataPermissionScopeEnum getByCode(Integer code) {
        Optional<DataPermissionScopeEnum> optional = Arrays.stream(DataPermissionScopeEnum.values()).filter(item -> item.code.equals(code)).findFirst();
        if (optional.isPresent()) {
            return optional.get();
        }

        throw new RuntimeException(String.format("编码%s存在枚举【DataPermissionScopeEnum】中不存在", code));
    }
}
